package interface_layer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import date_layer.Coordinator;

public class panel_sale extends JPanel implements ActionListener 
{
	private int num_bill = 1;
	private Coordinator coordinator;
	private JLabel Cake;
    private JLabel Image;
    private JLabel Information;
    private JLabel _client;
    private JComboBox cake;
    private JTextField client;
    //private JLabel fact;
    //private JTextField facttext;
    private JTextField id_vender;
    private JButton botonSearch;
    private JButton botonSave;
    private JScrollPane scroll_area;
    private JTextArea show_result_area;
    private JLabel vender;

    public panel_sale(Coordinator coordinator)
    {
    	this.coordinator = coordinator;
        initComponents();
    }

    private void initComponents()
    {
       // facttext = new JTextField();
        id_vender = new JTextField();
        botonSearch = new JButton();
        botonSave = new JButton();
        scroll_area = new JScrollPane();
        show_result_area = new JTextArea();
        //fact = new JLabel();
        Information = new JLabel();
        _client = new JLabel();
        vender = new JLabel();
        Cake = new JLabel();
        Image = new JLabel();
        client = new JTextField();
        cake = new JComboBox();

        setPreferredSize(new java.awt.Dimension(600, 380));
        setLayout(null);

       // add(facttext);
       // facttext.setBounds(20, 140, 190, 20);
        add(id_vender);
        id_vender.setBounds(20, 240, 190, 20);

        botonSearch.setText("Search");
        botonSearch.addActionListener(this);
        add(botonSearch);
        botonSearch.setBounds(20, 340, 75, 23);

        botonSave.setText("Save");
        botonSave.addActionListener(this);
        add(botonSave);
        botonSave.setBounds(140, 340, 70, 23);

        show_result_area.setColumns(20);
        show_result_area.setRows(5);
        scroll_area.setViewportView(show_result_area);

        add(scroll_area);
        scroll_area.setBounds(280, 20, 290, 320);

        //fact.setText("# Fact");
       // add(fact);
        //fact.setBounds(20, 120, 90, 14);

        Information.setText("Information");
        add(Information);
        Information.setBounds(280, 350, 200, 14);

        _client.setText("Client Id");
        add(_client);
        _client.setBounds(20, 170, 110, 14);

        vender.setText("Vender Id");
        add(vender);
        vender.setBounds(20, 220, 100, 14);

        Cake.setText("Cake");
        add(Cake);
        Cake.setBounds(20, 270, 90, 14);
        add(Image);
        Image.setBounds(20, 20, 250, 90);
        Image.setIcon(new ImageIcon("src\\images\\venta.png"));
        add(client);
        client.setBounds(20, 190, 190, 20);

        cake.setModel(new DefaultComboBoxModel(new String[] { "Chocolate", "Vanilla strawberries", "Maracuya" }));
        add(cake);
        cake.setBounds(20, 290, 190, 20);
    }

	
	public void actionPerformed(ActionEvent e)
	{
		//int num_bill  = coordinator.getSale().getBill();
		
		if ( e.getSource() == botonSave)
		{
			if (client.getText().equals("") ||  id_vender.getText().equals(""))
			{
				Information.setText("debe llenar todos los campos");
			}
			else
			{
				coordinator.manageSale(1, num_bill, null, null, null);
				num_bill++;
			}
		}
		else
		{
			if ( e.getSource() == botonSearch)
			{
				if (client.getText().equals("")  && id_vender.getText().equals(""))
				{
					Information.setText("debe llenar algun campo");
				}
				else
				{
					coordinator.manageSale(2, num_bill, null, null, null);
				}
			}
		}
	}
}
